﻿using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        GetRequest();
        BindDataList();
        LinkPage();
    }

    private static int nPage = 1;
    private int maxPage;
    private void LinkPage()
    {
        hyperLink_TrangTruoc.Visible = true;
        if (nPage == 1)
            hyperLink_TrangTruoc.Visible = false;
        int nextPage = nPage + 1;
        int prevPage = nPage - 1;
        hyperLink_TrangTruoc.NavigateUrl = "DanhMucSanPham.aspx?Page=" + prevPage;
        hyperLink_TrangKe.NavigateUrl = "DanhMucSanPham.aspx?Page=" + nextPage;
    }
    private void GetRequest()
    {
        if(Request["Page"]!=null)
            nPage = Int32.Parse(Request["Page"]);
    }
    private void BindDataList()
    {
        int MaDanhMucPhu = 1;
        if (Request["MaDanhMucPhu"] != null)
            MaDanhMucPhu = int.Parse(Request["MaDanhMucPhu"]);
        SanPhamDauGia_Ctl SPDG = new SanPhamDauGia_Ctl();
        SqlDataAdapter adapter = SPDG.DanhSachSanPhamDauGiaVoiDanhMuc(MaDanhMucPhu);
        DataSet dataSet = new DataSet();
        adapter.Fill(dataSet, (nPage - 1) * 20, 20, "SanPham");
        DL_DanhMucSanPham.DataSource = dataSet;
        DL_DanhMucSanPham.DataBind();        
    }
}
